﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMLSpreadGear.Core;
using System.Drawing;

namespace XMLSpreadGear.Headers
{
    public class Font:BaseElement
    {
        private bool? bBold;

        public bool? Bold
        {
            get { return bBold; }
            set { bBold = value; }
        }
        private string sColor = System.Drawing.Color.Black.ToString();

        public string Color
        {
            get { return sColor; }
            set { sColor = value; }
        }
        private string sFontName = "Arial";

        public string FontName
        {
            get { return sFontName; }
            set { sFontName = value; }
        }
        private bool? bItalic;

        public bool? Italic
        {
            get { return bItalic; }
            set { bItalic = value; }
        }
        private bool? bOutLine;

        public bool? OutLine
        {
            get { return bOutLine; }
            set { bOutLine = value; }
        }
        private bool? bShadow;

        public bool? Shadow
        {
            get { return bShadow; }
            set { bShadow = value; }
        }
        private double? dSize ;

        public double? Size
        {
            get { return dSize; }
            set { dSize = value; }
        }
        private bool? bStrikeThrough;

        public bool? StrikeThrough
        {
            get { return bStrikeThrough; }
            set { bStrikeThrough = value; }
        }
        private UnderLine uUnderLine = UnderLine.None;

        internal UnderLine UnderLine
        {
            get { return uUnderLine; }
            set { uUnderLine = value; }
        }
        private VerticalAlign vVerticalAlign = VerticalAlign.None;

        internal VerticalAlign VerticalAlign
        {
            get { return vVerticalAlign; }
            set { vVerticalAlign = value; }
        }
        private ulong? lCharSet;

        public ulong? CharSet
        {
            get { return lCharSet; }
            set { lCharSet = value; }
        }
        private Family fFamily = Family.Automatic;

        internal Family Family
        {
            get { return fFamily; }
            set { fFamily = value; }
        }


        public Font()
            : base(LocalNames.FONT)
        {
        }
        public Font(bool Bold, string Color, string FontName, bool Italic,
            bool Outline, bool Shadow, double Size, bool StrikeThrough, UnderLine Underline,
            VerticalAlign VerticalAlign, ulong Charset, Family Family)
            : this()
        {
            this.bBold = Bold;
            this.sColor = Color;
            this.sFontName = FontName;
            this.bItalic = Italic;
            this.bOutLine = Outline;
            this.bShadow = Shadow;
            this.dSize = Size;
            this.bStrikeThrough = StrikeThrough;
            this.uUnderLine = Underline;
            this.vVerticalAlign = VerticalAlign;
            this.lCharSet = Charset;
            this.fFamily = Family;
        }
        internal protected override IDictionary<string, string> RegisterElements()
        {
            IDictionary<string, string> dic = new Dictionary<string, string>();
            return dic;
        }

        internal protected override IDictionary<string, string> RegisterAttributes()
        {
            IDictionary<string, string> dic = new Dictionary<string, string>();

            dic.Add("Bold", this.Bold.ToByte().ToString());

            if (!string.IsNullOrEmpty(this.Color))
                dic.Add("Color", this.Color);

            if (!string.IsNullOrEmpty(this.FontName))
                dic.Add("FontName", this.FontName);

            dic.Add("Italic", this.Italic.ToByte().ToString());

            dic.Add("Outline", this.OutLine.ToByte().ToString());

            dic.Add("Shadow", this.Shadow.ToByte().ToString());

            if (this.Size != null)
                dic.Add("Size", this.Size.ToString());

            dic.Add("StrikeThrough", this.StrikeThrough.ToByte().ToString());

            dic.Add("Underline", Enum.GetName(typeof(UnderLine), this.UnderLine));

            if (this.VerticalAlign != null)
                dic.Add("VerticalAlign", Enum.GetName(typeof(VerticalAlign), this.VerticalAlign));

            dic.Add("CharSet", this.CharSet.ToString());

            if (this.Family != null)
                dic.Add("Family", Enum.GetName(typeof(Family), this.Family));

            return dic;
        }

        protected override void SetDefaults()
        {
            this.Bold = false;
            this.Color = "Black";
            this.FontName = "Arial";
            this.Italic = false;
            this.OutLine = false;
        }

        internal override string GetAttributeNamespace()
        {
            return Contstants.SpredsheetAttributePrefix;
        }

        internal override string GetAttributeNamespaceURI()
        {
            return Contstants.SpredsheetAttributeNamespace;
        }
    }
}
